<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	template="../../Template/TemplateAdmin.xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:t="http://myfaces.apache.org/tomahawk">


	<ui:define name="title">
		Trang Quản lý Quảng cáo
  	</ui:define>


	<ui:define name="content">

		<h:outputStylesheet library="css" name="quanlyquangcao.css" />
		<!-- Content -->
		<div id="MainPanel" align="left">

			<div class="ContentPart">
				<h1 class="ContentPartTitle" align="center">TRANG QUẢN LÝ QUẢNG
					CÁO</h1>
			</div>
			<div class="ContentPart">
				<h3 class="ContentPartHeader">Thao tác</h3>
				<div class="ContentPartContent">
					<div id="rightAction" align="right">

						<div class="actionLargeButton" align="center"
							onclick="ShowAddDialog()">
							<img class="buttonImage imgNoBackgroundBorder"
								src="../../Images/Icon/icon_addLarge.png" alt="Thêm" />
							<div class="buttonCaption">Thêm</div>
						</div>

						<!--  thẻ này là button dùng submit.. để ẩn, sẽ được gọi = js -->
						<!-- Thêm -->
						<h:commandLink id="btThem" styleClass="hidden"
							action="#{quanLyQuangCaoBean.ThemQuangCao()}">
							<!-- <div class="actionLargeButton" align="center">
								<img class="buttonImage imgNoBackgroundBorder"
									src="../../Images/Icon/icon_addLarge.png" alt="Thêm" />
								<div class="buttonCaption">Thêm N</div>
							</div> -->
						</h:commandLink>
						<!-- Sửa -->
						<h:commandLink id="btSua" styleClass="hidden"
							action="#{quanLyQuangCaoBean.SuaQuangCao()}">
							<!-- <div class="actionLargeButton" align="center">
								<img class="buttonImage imgNoBackgroundBorder"
									src="../../Images/Icon/icon_addLarge.png" alt="Thêm" />
								<div class="buttonCaption">Sửa N</div>
							</div> -->
						</h:commandLink>
						<!-- đóng thẻ ẩn -->

						<h:commandLink immediate="true"
							action="#{quanLyQuangCaoBean.LietKeToanBo()}">
							<div class="actionWideButtonRight" align="center">
								<img class="buttonImage imgNoBackgroundBorder"
									src="../../Images/Icon/icon_lietKeLarge.png" alt="Liệt kê" />
								<div class="buttonCaption">Liệt kê toàn bộ</div>
							</div>
							<f:ajax render="tableContent" />
						</h:commandLink>
					</div>
					<div id="leftAction">
						<div class="ins">Tìm kiếm Quảng cáo</div>
						<div id="Search">
							<h:inputText id="inputTim" class="txtField" type="text"
								value="#{quanLyQuangCaoBean.chuoiTimKiem}" />
							<h:commandLink action="#{quanLyQuangCaoBean.TimKiem()}"
								outcom="TrangQuanLyQuangCao">
								<div id="btSearch">Tìm</div>
							</h:commandLink>
						</div>
					</div>
				</div>
			</div>
			<!-- Content -->
			<div class="ContentPart">
				<div class="ContentPartContent">
					<h:messages id="messageNotification" />
				</div>
			</div>
			<div class="ContentPart">
				<h3 class="ContentPartHeader">Danh sách Quảng cáo</h3>
				<h:panelGroup id="tableContent">
					<h:dataTable value="#{quanLyQuangCaoBean.lstQuangCao}" var="qc"
						styleClass="tableDulieu"
						rendered="#{not empty quanLyQuangCaoBean.lstQuangCao}"
						rowClasses="rowLe,rowChan">

						<ui:param name="index"
							value="#{quanLyQuangCaoBean.lstQuangCao.indexOf(qc)}" />

						<h:column>
							<f:facet name="header">STT</f:facet>
							<h:outputText value="#{index + 1}" />
						</h:column>
						<h:column>
							<f:facet name="header">Hình ảnh</f:facet>
							<!-- <img class="imgQuangCaoReview imgNoBackgroundBorder" align="middle"
								src="../../Images/Ads/#{qc.hinhanh}" /> -->
							<h:graphicImage
								styleClass="imgQuangCaoReview imgNoBackgroundBorder"
								value="../../Images/Ads/#{qc.hinhanh}" />
							<!-- <h:graphicImage styleClass="productImage imgNoBackgroundBorder"
								url="../../Images/Ads/hinhquangcao01.jpg" /> -->
						</h:column>
						<h:column>
							<f:facet name="header">Tên Công ty</f:facet>
							<h:outputText value="#{qc.congty}" />
						</h:column>
						<h:column>
							<f:facet name="header">Link</f:facet>
							<h:outputLink value="#{qc.link}">
							#{qc.link}
							</h:outputLink>
							<!-- <a href="#{qc.link}" target="_blank"> 
							#{qc.link}
							<h:outputText value="#{qc.link}" />
							</a> -->
						</h:column>
						<h:column>
							<f:facet name="header">Vùng quảng cáo</f:facet>
							<h:outputText value="#{qc.vungquangcao}" />
						</h:column>
						<h:column>
							<f:facet name="header"> Đã xóa</f:facet>
							<h:outputText value="Xóa" rendered="#{qc.daxoa}" />
							<h:outputText value="Chưa" rendered="#{not qc.daxoa}" />
						</h:column>
						<h:column>
							<f:facet name="header">Thao tác</f:facet>
							<div class="thaoTacCol">
								<h:commandButton
									class="deleteIcon no-border pointerCursor flowToLeft"
									process="@this" immediate="true"
									onclick="if (confirm ('Bạn có chắc chắc muốn xóa (hoàn toàn) Quảng cáo này?')) return true; return false;"
									action="#{quanLyQuangCaoBean.Xoa(qc)}" alt="Xóa"
									rendered="#{not qc.daxoa}" />
								<h:commandButton
									class="editIcon no-border pointerCursor flowToLeft"
									immediate="true" onclick="setTimeout(ShowEditDialog,500);"
									action="#{quanLyQuangCaoBean.SetMaQuangCaoAndGetData(qc.maquangcao)}"
									alt="Sửa">
									<f:ajax execute="@this" render="@form" />
								</h:commandButton>
								<h:commandButton
									class="acceptIcon no-border pointerCursor flowToLeft"
									process="@this" immediate="true"
									onclick="if (confirm ('Bạn có chắc chắc muốn Hủy xóa Quảng cáo này?')) return true; return false;"
									action="#{quanLyQuangCaoBean.HuyXoa(qc)}"
									outcome="TrangQuanLyQuangCao" alt="Hủy Xóa"
									rendered="#{qc.daxoa}" />
							</div>
						</h:column>
					</h:dataTable>
				</h:panelGroup>
			</div>

		</div>
		<!-- Content -->
		<h:outputScript library="js" name="TrangQuanLyQuangCao.js"
			target="head" />

		<div id="addQuangCao" class="hidden">
			<!-- <h:form id="dialogForm" prependId="false"
				enctype="multipart/form-data"> -->
			<p>Tên Công ty</p>
			<h:inputText value="#{quanLyQuangCaoBean.congTy}" />
			<p>Link</p>
			http://<h:inputText value="#{quanLyQuangCaoBean.link}" />
			<p>Chọn vùng quảng cáo</p>
			<!-- <h:inputText value="#{quanLyQuangCaoBean.vungQuangCao}" /> -->
			<h:selectOneMenu name="cbbVungQuangCao" id="cbbVungQuangCao"
				class="combobox" value="#{quanLyQuangCaoBean.vungQuangCao}">
				<f:selectItem itemValue="1" itemLabel="Vùng 1" />
				<f:selectItem itemValue="2" itemLabel="Vùng 2" />
				<f:selectItem itemValue="3" itemLabel="Vùng 3" />
				<f:selectItem itemValue="4" itemLabel="Vùng 4" />
				<f:selectItem itemValue="5" itemLabel="Vùng 5" />
			</h:selectOneMenu>
			<p>Hình ảnh</p>
			<t:inputFileUpload value="#{quanLyQuangCaoBean.uploadedFile}" />
			<br />
			<p>
				<b>Ghi Chú:</b> Sẽ thay thế quảng cáo<br /> đã có sẵn ở vùng được
				chọn<br /> (nếu có).
			</p>
			<br />
			<div id="dialogBTThem">
				<h:commandButton class="dialogButton buttonLink button" value="Thêm"
					action="#{quanLyQuangCaoBean.ThemQuangCao()}" />
			</div>
			<div id="dialogBTSua">
				<h:commandButton class="dialogButton buttonLink button" value="Sửa"
					action="#{quanLyQuangCaoBean.SuaQuangCao()}" />
			</div>
			<!-- </h:form> -->
		</div>
		<!-- Dialog -->
	</ui:define>
</ui:composition>